package org.jeecg.modules.zonglzp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.zonglzp.entity.BusinesswaterEntity;
import org.jeecg.modules.zonglzp.entity.store;
import org.jeecg.modules.zonglzp.mapper.BusinesswaterMapper;
import org.jeecg.modules.zonglzp.service.BusinesswaterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class BusinesswaterServiceImpl implements BusinesswaterService {

    @Autowired
    BusinesswaterMapper mapper;

    //查询我的报表
    @Override
    public IPage<BusinesswaterEntity> getBusinesswater(Page<BusinesswaterEntity> page, String starttime, String endtime, String storeCode, String userid,String orgCode,String storeId) {
        IPage<BusinesswaterEntity> pageList = mapper.getBusinesswater(page, starttime, endtime, storeCode, userid,orgCode,storeId);
        if (pageList != null) {
            for (int i = 0; i < pageList.getRecords().size(); i++) {
                pageList.getRecords().get(i).setCreateTime(pageList.getRecords().get(i).getCreateTime().substring(0, 19));

                if( pageList.getRecords().get(i).getType()==1){
                    pageList.getRecords().get(i).setStoreName(mapper.getstoreNamebyStoreCode( pageList.getRecords().get(i).getStoreId()));
                }
            }
        }
        return pageList;
    }


    //查询账号充值页面金额内容
    @Override
    public Map<String, Object> getmoneydetail(String token) {
        return mapper.getmoneydetail(token);
    }


    //账号充值页面 查询某日流水
    @Override
    public IPage<BusinesswaterEntity> getonedaydetail(Page<BusinesswaterEntity> page, String userid, String today, String starttime, String endtime) {
        return mapper.getonedaydetail(page, userid, today, starttime, endtime);
    }


    //查询已完成或者未完成单据 面料的
    @Override
    public IPage<BusinesswaterEntity> getmianliaobill(Page<BusinesswaterEntity> page, String starttime, String endtime, String storeCode, String userid, int ddstatus) {
        return mapper.getmianliaobill(page, starttime, endtime, storeCode, userid, ddstatus);
    }


    //查询已完成或者未完成的单据 面料的
    @Override
    public IPage<BusinesswaterEntity> getgedingbill(Page<BusinesswaterEntity> page, String starttime, String endtime, String storeCode, String userid, int ddstatus) {
        return mapper.getgedingbill(page, starttime, endtime, storeCode, userid, ddstatus);
    }

    //查询已完成或者未完成的报表
    @Override
    public IPage<BusinesswaterEntity> getBusinesswater(Page<BusinesswaterEntity> page, String starttime, String endtime, String storeCode, String userid, int ddstatus,String orgCode,String storeId) {
        IPage<BusinesswaterEntity> pageList = mapper.getBusinesswatertwo(page, starttime, endtime, storeCode, userid, ddstatus,orgCode,storeId);

        if (pageList != null) {
            for (int i = 0; i < pageList.getRecords().size(); i++) {
                pageList.getRecords().get(i).setCreateTime(pageList.getRecords().get(i).getCreateTime().substring(0, 19));

                if( pageList.getRecords().get(i).getType()==1){
                    pageList.getRecords().get(i).setStoreName(mapper.getstoreNamebyStoreCode( pageList.getRecords().get(i).getStoreId()));
                }
            }



        }
        return pageList;
    }

    //查询已完成和未完成金额
    @Override
    public Double moneyStatistics(String starttime, String endtime, String storeCode, String userid, int ddstatus, String orgCode, String storeId) {
        return mapper.moneyStatistics(starttime, endtime, storeCode, userid, ddstatus,orgCode,storeId);
    }

    //根据团订编号获取门店详情
    @Override
    public store getstoreDetailByorderSn(String orderSn) {
        return mapper.getstoreDetailByorderSn(orderSn) ;
    }
}
